package com.it.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@ComponentScan("com.it")
@EnableWebMvc  // 帮我们自动加上 handlerMapping、handlerAdapter、JSON转换器
public class springmvcConfig implements WebMvcConfigurer {

    /**
     * 配置视图解析器，指定前后缀
     * 【步骤】：1、实现WebMvcConfigurer接口
     * 2、实现 configureViewResolvers方法
     */
    public void configureViewResolvers(ViewResolverRegistry registry) {
        // registry 可以快速添加前后缀
        registry.jsp("/WEB-INF/views", ".jsp");
        // 如果想找到这个视图 直接返回index即可
    }

    /**
     * 开启静态资源查找 /img/keshihuadapin.png
     */
    @GetMapping("/data1")
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
